/**
 * 查看自己感兴趣的或参加的活动
 */
package org.morningangel.servlet.android;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.morningangel.android.bean.SearchActivityList;
import org.morningangel.bean.Activity;
import org.morningangel.dao.StatusDao;
import org.morningangel.dao.impl.StatusDaoImpl;

@WebServlet(name = "AndroidMyActivityServlet", urlPatterns = "/android/myActivity")
public class MyActivityServlet extends HttpServlet {
	private static final long serialVersionUID = -5785283418885794955L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Integer userId = Integer.parseInt(request.getParameter("userId"));
		String joined = request.getParameter("joined");
		//String interested = request.getParameter("interested");
		StatusDao statusDao = new StatusDaoImpl();
		SearchActivityList result = null;
		List<Activity> activities = null;
		if (joined != null && joined.equals("1")) {
			activities = statusDao.getActivities(userId, 2);
		} else {
			activities = statusDao.getActivities(userId, 1);
		}
		result = new SearchActivityList(activities);
		JSONObject jsonObject = JSONObject.fromObject(result);
		PrintWriter out = response.getWriter();
		out.print(jsonObject.toString());
		out.flush();
		out.close();
	}

}
